package com.itheima.stream;

import java.util.*;
import java.util.stream.Collectors;

public class StreamDemo07 {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        Collections.addAll(list,1,2,3,4,4,4,4,5);

        //public static <T> Collector toList()
        List<Integer> ListCollect = list.stream().filter(num -> num % 2 == 0)
                .collect(Collectors.toList());
        System.out.println(ListCollect);//[2, 4, 4, 4, 4]


        //public static <T> Collector toSet()
        Set<Integer> SetCollect = list.stream().collect(Collectors.toSet());
        System.out.println(SetCollect);//[1, 2, 3, 4, 5]


        ArrayList<String> list1 = new ArrayList<>();
        Collections.addAll(list1,"k1,v1","k2,v2","k3,v3");

        //public static  Collector toMap(Function keyMapper,Function valueMapper)
        Map<String, String> MapCollect = list1.stream().collect(Collectors.toMap(
                s -> s.split(",")[0],
                s -> s.split(",")[1]
        ));
        System.out.println(MapCollect);//{k1=v1, k2=v2, k3=v3}
    }
}
